package br.com.site.model.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import br.com.site.model.dao.ParametrosSistemaDAO;
import br.com.site.model.dao.DAOException;
import br.com.site.model.dao.DAOFactory;

@Entity
public class ParametrosSistema implements
		CrudBaseEntity<ParametrosSistema, Long>, Auditoria {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1818841017643045298L;

	@Id
	@GeneratedValue
	private Long id;

	private String tituloSistema;
	private String versao;
	private String tamListagem;
	private String smtpServer;
	private String portaSMTP;
	private String popServer = "";
	private String portaPOP;
	private String loginMail = "";
	private String senhaMail = "";
	private String contaEmail;
	private String prefixoTituloMail;
	@Column(columnDefinition="text")
	private String feiraHome;
	
	/* Auditoria */
	@Column(name = "loginUsuario", nullable = false)
	private String loginUsuario;

	@Column(name = "dtCriacao", nullable = false)
	private Date dtCriacao;

	@Column(name = "dtModificacao", nullable = false)
	private Date dtModificacao;

	@Column(name = "ativo", nullable = false)
	private boolean ativo;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getTituloSistema() {
		return tituloSistema;
	}

	public void setTituloSistema(String tituloSistema) {
		this.tituloSistema = tituloSistema;
	}

	public String getVersao() {
		return versao;
	}

	public void setVersao(String versao) {
		this.versao = versao;
	}

	public String getTamListagem() {
		return tamListagem;
	}

	public void setTamListagem(String tamListagem) {
		this.tamListagem = tamListagem;
	}

	public String getSmtpServer() {
		return smtpServer;
	}

	public void setSmtpServer(String smtpServer) {
		this.smtpServer = smtpServer;
	}

	public String getPopServer() {
		return popServer;
	}

	public void setPopServer(String popServer) {
		this.popServer = popServer;
	}

	public String getLoginMail() {
		return loginMail;
	}

	public void setLoginMail(String loginMail) {
		this.loginMail = loginMail;
	}

	public String getSenhaMail() {
		return senhaMail;
	}

	public void setSenhaMail(String senhaMail) {
		this.senhaMail = senhaMail;
	}

	public String getPrefixoTituloMail() {
		return prefixoTituloMail;
	}

	public void setPrefixoTituloMail(String prefixoTituloMail) {
		this.prefixoTituloMail = prefixoTituloMail;
	}


	public String getLoginUsuario() {
		return loginUsuario;
	}

	public void setLoginUsuario(String loginUsuario) {
		this.loginUsuario = loginUsuario;
	}

	public Date getDtCriacao() {
		return dtCriacao;
	}

	public void setDtCriacao(Date dtCriacao) {
		this.dtCriacao = dtCriacao;
	}

	public Date getDtModificacao() {
		return dtModificacao;
	}

	public void setDtModificacao(Date dtModificacao) {
		this.dtModificacao = dtModificacao;
	}

	public boolean isAtivo() {
		return ativo;
	}

	public void setAtivo(boolean ativo) {
		this.ativo = ativo;
	}

	public String getContaEmail() {
		return contaEmail;
	}

	public void setContaEmail(String contaEmail) {
		this.contaEmail = contaEmail;
	}

	public String getPortaSMTP() {
		return portaSMTP;
	}

	public void setPortaSMTP(String portaSMTP) {
		this.portaSMTP = portaSMTP;
	}

	public String getPortaPOP() {
		return portaPOP;
	}

	public void setPortaPOP(String portaPOP) {
		this.portaPOP = portaPOP;
	}

	@Override
	public void remove() throws BusinessException {
		DAOFactory factory = DAOFactory.getInstance();
		try {
			factory.txBegin();
			ParametrosSistemaDAO dao = factory
					.getDao(ParametrosSistemaDAO.class);
			dao.remove(this.id);

			factory.txCommit();
		} catch (DAOException e) {
			factory.txRollback();
			throw new BusinessException(e);
		} finally {
			factory.shutdown();
		}

	}

	
	public String getFeiraHome() {
		return feiraHome;
	}

	public void setFeiraHome(String feiraHome) {
		this.feiraHome = feiraHome;
	}

	@Override
	public void save() throws BusinessException {

		DAOFactory factory = DAOFactory.getInstance();
		try {
			factory.txBegin();
			ParametrosSistemaDAO dao = factory
					.getDao(ParametrosSistemaDAO.class);
			dao.save(this);

			factory.txCommit();
		} catch (DAOException e) {
			factory.txRollback();
			throw new BusinessException(e);
		} finally {
			factory.shutdown();
		}
	}

	public static ParametrosSistema find(Long oid) {
		DAOFactory factory = DAOFactory.getInstance();
		ParametrosSistemaDAO dao = factory.getDao(ParametrosSistemaDAO.class);

		return dao.find(oid);
	}

	public static List<ParametrosSistema> find() {
		DAOFactory factory = DAOFactory.getInstance();
		ParametrosSistemaDAO dao = factory.getDao(ParametrosSistemaDAO.class);

		return dao.find();
	}

	public static List<ParametrosSistema> findByCriteria(
			ParametrosSistema avisoMural) {
		DAOFactory factory = DAOFactory.getInstance();
		ParametrosSistemaDAO dao = factory.getDao(ParametrosSistemaDAO.class);

		return dao.findByCriteria(avisoMural);
	}

	public static List<ParametrosSistema> find(int first, int max) {
		DAOFactory factory = DAOFactory.getInstance();
		ParametrosSistemaDAO dao = factory.getDao(ParametrosSistemaDAO.class);

		return dao.find(first, max);
	}

	public static List<ParametrosSistema> findByCriteria(
			ParametrosSistema avisoMural, int first, int max) {
		DAOFactory factory = DAOFactory.getInstance();
		ParametrosSistemaDAO dao = factory.getDao(ParametrosSistemaDAO.class);

		return dao.findByCriteria(avisoMural, first, max);

	}

	public boolean equals(Object obj) {
		boolean bool = false;
		if (obj instanceof ParametrosSistema)
			bool = hashCode() == ((ParametrosSistema) obj).hashCode();
		return bool;
	}

}